package com.test.jsonb;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

public class Booktest {

	// Plumbing code removed for brevity
	   public static void main(String[] args) throws Exception {
		   Book book = new Book("ABCD-1234", "Fun with Java", "Alex Theedom");
		   Jsonb jsonb = JsonbBuilder.create();
		   String json = adaptToJson(book).toString();
		   System.out.println(json);
//			No default constructor found
		   Book book1=jsonb.fromJson(json, Book.class);
		   System.out.println(book1.getAuthor());
	   	}
	   //自定义了顺序
	   public static JsonObject adaptToJson(Book book) throws Exception {
		   return Json.createObjectBuilder()
		        .add("title", book.getTitle())
		        .add("author", book.getAuthor())
		        .add("id", book.getId())
		        .build();
		}
}
